﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Devonline.Identity.Admin.Controllers;

/// <summary>
/// 组织部门管理
/// </summary>    
[Route("api/[controller]")]
[ApiController]
[SecurityHeaders]
[Authorize(Roles = GROUP_MAINTAINERS)]
public class GroupsController(
    ILogger<GroupsController> logger,
    IDataWithAttachmentService<Group> dataService,
    GroupStore groupStore) :
    ODataModelServiceController<Group, GroupViewModel>(logger, dataService)
{
    private readonly GroupStore _groupStore = groupStore;

    /// <summary>
    /// 获取子级组织机构
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("GetChildrenGroups/{id}")]
    public async Task<IActionResult> GetChildrenGroupsAsync(string id) => Ok(await _groupStore.GetChildrenGroupsAsync(id, Request.GetRequestOption<bool>("recursion")));
}